package com.ruoyi.project.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.MonthlyImage;
import com.ruoyi.project.service.IMonthlyImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月度形象图Controller
 * 
 * @author liboyu
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/project/monthImage")
public class MonthlyImageController extends BaseController
{
    @Autowired
    private IMonthlyImageService monthlyImageService;

    /**
     * 查询月度形象图列表
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonthlyImage monthlyImage)
    {
//        startPage();
        List<MonthlyImage> list = monthlyImageService.selectMonthlyImageList(monthlyImage);
        return getDataTable(list);
    }

    /**
     * 导出月度形象图列表
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:export')")
    @Log(title = "月度形象图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonthlyImage monthlyImage)
    {
        List<MonthlyImage> list = monthlyImageService.selectMonthlyImageList(monthlyImage);
        ExcelUtil<MonthlyImage> util = new ExcelUtil<MonthlyImage>(MonthlyImage.class);
        util.exportExcel(response, list, "月度形象图数据");
    }

    /**
     * 获取月度形象图详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(monthlyImageService.selectMonthlyImageByImageId(imageId));
    }

    /**
     * 新增月度形象图
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:add')")
    @Log(title = "月度形象图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MonthlyImage monthlyImage)
    {
        //唯一验证
        Long id =monthlyImageService.checkNameUnique(monthlyImage);
        if (id != null){
            return error("已有同名主题,不能添加");
        }
        return toAjax(monthlyImageService.insertMonthlyImage(monthlyImage));
    }

    /**
     * 修改月度形象图
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:edit')")
    @Log(title = "月度形象图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MonthlyImage monthlyImage)
    {
        //唯一验证
        Long id =monthlyImageService.checkNameUnique(monthlyImage);
        if (id != null){
            return error("已有同名主题,不能修改");
        }
        return toAjax(monthlyImageService.updateMonthlyImage(monthlyImage));
    }

    /**
     * 删除月度形象图
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:remove')")
    @Log(title = "月度形象图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(monthlyImageService.deleteMonthlyImageByImageIds(imageIds));
    }
}
